function initPeaks(buffer, width){

  if(!buffer)return;

  let first = 0,
    last = parseInt(width / 7);
  let peaks = [];

  const sampleSize = (buffer.length / width) * 7;
  const sampleStep = ~~(sampleSize / (10*7)) || 1;

  const chan = buffer.getChannelData(0);

  let i;

  for (i = first; i <= last; i++) {
    const start = ~~(i * sampleSize);
    const end = ~~(start + sampleSize);
    let min = 0;
    let max = 0;
    let j;

    for (j = start; j < end; j += sampleStep) {
      const value = chan[j];

      if (value > max) {
        max = value;
      }

      if (value < min) {
        min = value;
      }
    }

    peaks[2 * i] = max;

    peaks[2 * i + 1] = min;

  }

  return Math.abs((peaks[0]+peaks[1])/2)
}

export default initPeaks